<template>
  <div class="fillcontain">
    <head-top></head-top>
    <div class="table_container">
      <el-table
        :data="tableData"
        style="width: 100%">
        <el-table-column
          prop="bookName"
          label="书籍名"
          width="180">
        </el-table-column>
        <el-table-column
          prop="bookAuthor"
          label="书籍作者"
          width="220">
        </el-table-column>
        <el-table-column
          label="书籍封面"
          width="180" height="150">
          <template slot-scope="scope">
             <img :src="scope.row.bookCover" />
          </template>
        </el-table-column>
        <el-table-column
          prop="bookPub"
          label="权限">
        </el-table-column>
      </el-table>
      <div class="Pagination" style="text-align: left;margin-top: 10px;">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-size="5"
          layout="total, prev, pager, next"
          :total="count">
        </el-pagination>
        <el-button type="primary" @click="getData"> 请求数据</el-button>
        <p> {{ tableData }}</p>
      </div>
    </div>
  </div>
</template>

<script>
  import headTop from '@/components/headTop'
  import {mapGetters} from 'vuex'
  export default {
    name: "book",
    components: {
      headTop
    },
    data(){
      return {
        tableData: [],
        currentRow: null,
        offset: 0,
        limit: 20,
        count: 0,
        currentPage: 1,
      }
    },
    created: function () {
      console.log('created....');
      this.$store.dispatch('getMineBaseApi');
    },
    computed: {
      // tableData: function () {
      //   console.log(this.$store.state.getMineBaseMsg.books)
      //   let tableData = []
      //   this.$store.state.getMineBaseMsg.books.forEach(item =>{
      //   const tableItem = {
      //     bookName: item.bookName,
      //     bookAuthor: item.bookAuthor,
      //     bookCover: item.bookCover,
      //     bookSummary: item.bookSummary
      //   }
      //   tableData.push(tableItem)
      //   })
      //   return tableData;
      // }
    },
    methods: {
      async initData(err) {
        this.$store.dispatch('getBookInfo')
          .then(
            alert('Dispath')
          );
        let bookInfo = this.$store.state.bookInfo;
        this.tableData = bookInfo.books;
        console.log('Store bookInfo'+bookInfo)
        this.count = bookInfo.bookCount;
      },
      getData() {
        console.log('getData()...');
        this.$store.dispatch('getBookInfo');
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.currentPage = val;
        this.offset = (val - 1)*this.limit;
        this.getAdmin()
      },
    }
  }

</script>

<style scoped>
  img{
  max-height: 200px;
  }

</style>
